﻿<%@ Page ValidateRequest="false" Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="Send.aspx.cs" Inherits="IMark.Admin.EmailMarketing.Send" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <!-- DataTables CSS -->
    <link href="<%= ResolveClientUrl("~/Admin/css/plugins/dataTables.bootstrap.css") %>" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <input type="hidden" id="ResolveClientUrl" value="<%= ResolveClientUrl("~/") %>" />
    <input id="lstProductAdd" type="hidden" value="" />
    <div class="row">
        <div class="col-lg-12">
            <div id="info" runat="server"></div>
            <div class="panel panel-green">
                <div class="panel-heading">
                    Gửi Email Quảng Cáo Sản Phẩm                       
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="form-group">
                        <label>Tiêu đề email <span class="irequire">(*)</span></label>
                        <input id="txtEmailTitle" runat="server" placeholder="Nhập Tiêu đề email" class="form-control validate[required]" data-prompt-position="topLeft" />
                    </div>

                    <div class="form-group">
                        <label>Nội dung email <span class="irequire">(*)</span></label>
                        <textarea id="txtContent" runat="server" rows="2" class="form-control"></textarea>
                    </div>

                    <!-- /.table-responsive -->
                    <asp:Button ID="btnSend" runat="server" CssClass="btn btn-primary" Text="Gửi" OnClick="btnSend_Click" />
                    <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-primary" Text="Thoát" UseSubmitBehavior="false" OnClick="btnCancel_Click" />

                    <button data-toggle="modal" data-target="#modalAddProductToMail" class="btn btn-danger" type="button" title="Thêm sản phẩm"><i class="fa fa-plus"></i>Thêm Sản Phẩm</button>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
    
    <div aria-hidden="false" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="modalAddProductToMail" class="modal fade in">
        <div class="modal-backdrop fade in"></div>
        <div class="modal-dialog">
            <div class="modal-content" style="overflow: auto;">
                <div class="modal-header">
                    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h4 id="myModalLabel" class="modal-title">Thêm sản phẩm vào email gửi cho khách hàng</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="panel panel-green">
                                <div class="panel-heading">
                                    Danh Sách Sản Phẩm
                                </div>
                                <!-- /.panel-heading -->
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <input type="hidden" id="lstIDProduct" value="" />
                                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                            <thead>
                                                <tr>
                                                    <th class="no-sort"></th>
                                                    <th class="no-sort"></th>
                                                </tr>
                                            </thead>
                                            <tbody id="lstProduct" runat="server">
                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- /.table-responsive -->

                                </div>
                                <!-- /.panel-body -->
                            </div>
                            <!-- /.panel -->
                        </div>
                        <!-- /.col-lg-12 -->
                    </div>
                </div>
                <div class="modal-footer">
                    <button data-dismiss="modal" class="btn btn-default" type="button">Hủy</button>
                    <button onclick="addToBodyMail()" class="btn btn-primary">Hoàn tất</button>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Footer" runat="server">
    <script src="<%= ResolveClientUrl("~/Editor/ckeditor/ckeditor.js") %>"></script>
    <!-- DataTables JavaScript -->
    <script src="<%= ResolveClientUrl("~/Admin/js/plugins/dataTables/jquery.dataTables.js") %>"></script>
    <script src="<%= ResolveClientUrl("~/Admin/js/plugins/dataTables/dataTables.bootstrap.js") %>"></script>

    <script type="text/javascript">
        var content = "<%= txtContent.ClientID %>";
        CKEDITOR.replace(content);
        $(document).ready(function () {
            $("#aspnetForm").validationEngine();
            var wHeight = $(window).height();
            $("#modalAddProductToMail .modal-content").height((wHeight - 60) + "px");
            $('#dataTables-example').dataTable({
                "bLengthChange": false,
                "pageLength": 10,
                "bInfo": false
            });
            $("#dataTables-example_wrapper .row:first .col-sm-6:first").html("<button onclick=\"addToBodyMail()\" class=\"btn btn-primary\">Hoàn tất</button>");
        });
        //ham nay fai de sau ckeditor.js
        function addToBodyMail() {            
            var lstCurentID = $("#lstProductAdd").val();
            if (lstCurentID == "") {
                alert('Vui lòng chọn ít nhất 1 sản phẩm để gửi mail trước khi hoàn tất.');                                
            } else {
                //modalAddProductToMail.close                
                $("#modalAddProductToMail").modal('hide')
                $.ajax({
                    type: "POST",
                    async: false,
                    url: $("#ResolveClientUrl").val() + "Admin/Ajax/EmailMarketing.aspx/ProductSendMail",
                    data: JSON.stringify({
                        listIDProduct: lstCurentID
                    }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        $("#lstProductAdd").val("");
                        var editor = CKEDITOR.instances.ctl00_ContentPlaceHolder1_txtContent;
                        if (editor.mode == 'wysiwyg') {
                            editor.insertHtml(msg.d);
                        } else {
                            alert('Vui lòng không chọn chế độ Source');
                        }
                    }
                });
            }
        }
    </script>
</asp:Content>
